import React, { useState } from 'react'

export default function App () {
  //作用： 提供状态和修改状态的方法
  //参数：代表默认值
  // 返回值：数组[初始化数据，修改数据的方法]
  console.log(1);
  const [count, setCount] = useState(() => {
    console.log(2);
    let sum = 0
    for (let i = 0; i <= 10; i++) {
      sum += i
    }
    return sum
  })
  const handleCick = () => {
    setCount(count + 1)

  }
  return (
    <div>
      <h2> 计数器：{count}</h2>

      <button onClick={handleCick}>+1</button>
    </div>
  )
}

